// 引入 Request
import Request from './index.js'
import {url1,url2} from '@/api/common.js'



//    http://localhost:8081/#/pages/ainit/ainit?token=1asasasa


var token= uni.getStorageSync('token')
var tokenNum = 0
// let token =''
const config1 = {
	baseUrl: url1,
	header: {"Content-Type": "application/json","token":token},
	cancelReject: {
		text: '请求未通过验证,检查是否登录或者数据正确',
		type: 'warning'
	},
	failReject: {
		type: 'error',
		text: "网络异常，请求发送失败，请检查网络"
	}
}
const config2 = {
	baseUrl: url2,
	header: {"Content-Type": "application/json","token":token},
	cancelReject: {
		text: '请求未通过验证,检查是否登录或者数据正确',
		type: 'warning'
	},
	failReject: {
		type: 'error',
		text: "网络异常，请求发送失败，请检查网络"
	}
}


// 请求前拦截
const reqInterceptor1 = async (options) => { 
	return options
}

// 请求前拦截
const reqInterceptor2 = async (options) => { 
	options.header.token = token
	if(options.header.token ==''){
		uni.showToast({
			title:'未登录',
			icon:'none'
		})
		token= uni.getStorageSync('token') 
		if(token!= ''){ 
			return
		}else{ 
			return false
		}
		
	}
	return options
}
// 响应后拦截
const resInterceptor1 = (response, conf={}) => { 
	return response.data
}
const resInterceptor2 = (response, conf={}) => {
	
	return response.data
}
// 优品 正常请求
export const req1 = new Request(config1, reqInterceptor1, resInterceptor1)

// 剧豆 正常请求
export const req2 = new Request(config2, reqInterceptor1, resInterceptor1)

// 优品 携带 token 请求
export const req3 = new Request(config1, reqInterceptor2, resInterceptor2)

// 剧豆 携带 token 请求
export const req4 = new Request(config2, reqInterceptor2, resInterceptor2)